var ajax = new Array();
 
function getPlanta(sel) {
	var countryCode = sel.options[sel.selectedIndex].value;
	document.getElementById('planta').options.length = 0;	// Empty city select box
	if(countryCode.length>0){
		var index = ajax.length;
		ajax[index] = new sack();
		ajax[index].requestFile = 'get.php?tid='+countryCode;	// Specifying which file to get
		ajax[index].onCompletion = function(){ createCities(index) };	// Specify function that will be executed after file has been found
		ajax[index].runAJAX();		// Execute AJAX function
	}
}
function getPlantaCon(sel) {
	var countryCode = sel.options[sel.selectedIndex].value;
	document.getElementById('planta').options.length = 0;	// Empty city select box
	if(countryCode.length>0){
		var index = ajax.length;
		ajax[index] = new sack();
		ajax[index].requestFile = 'get.php?tid='+countryCode+'&con=si';	// Specifying which file to get
		ajax[index].onCompletion = function(){ createCities(index) };	// Specify function that will be executed after file has been found
		ajax[index].runAJAX();		// Execute AJAX function
	}
}
function getPlantaCon2(sel) {
	var countryCode = sel.options[sel.selectedIndex].value;
	document.getElementById('planta2').options.length = 0;	// Empty city select box
	if(countryCode.length>0){
		var index = ajax.length;
		ajax[index] = new sack();
		ajax[index].requestFile = 'get.php?tid='+countryCode+'&con=si';	// Specifying which file to get
		ajax[index].onCompletion = function(){ createCities2(index) };	// Specify function that will be executed after file has been found
		ajax[index].runAJAX();		// Execute AJAX function
	}
}
function createCities(index) {
	var obj = document.getElementById('planta');
	eval(ajax[index].response);	// Executing the response from Ajax as Javascript code	
}
function createCities2(index) {
	var obj = document.getElementById('planta2');
	eval(ajax[index].response);	// Executing the response from Ajax as Javascript code
}
function popup(htmlfile, ancho, alto, titulo){
	window.open(htmlfile,titulo,"toolbar=no,width="+ancho+",height="+alto+",status=no,scrollbars=yes,resizable=yes,menubar=no")
}

////////////////////////////////////////////////////////////////////
//////////////////// INICIO ////////////////////////////////////////
/////////// SCRIPT PARA GRID DE ORDENAMIENTO ///////////////////////
////////////////////////////////////////////////////////////////////

var tableWidget_okToSort = true;
var tableWidget_arraySort = new Array();
tableWidget_tableCounter = 1;
var activeColumn = new Array();
var currentColumn = false;

function sortNumeric(a,b){
	a = a.replace(/,/,'.');
	b = b.replace(/,/,'.');
	a = a.replace(/[^\d\.\/]/g,'');
	b = b.replace(/[^\d\.\/]/g,'');
	if(a.indexOf('/')>=0)a = eval(a);
	if(b.indexOf('/')>=0)b = eval(b);
	return a/1 - b/1;
}
	
function sortString(a, b) {
	if ( a.toUpperCase() < b.toUpperCase() ) return -1;
	if ( a.toUpperCase() > b.toUpperCase() ) return 1;
	return 0;
}
		
function sortTable() {
	if (!tableWidget_okToSort) return;
	tableWidget_okToSort = false;
	/* Getting index of current column */
	var obj = this;
	var indexThis = 0;
	while(obj.previousSibling) {
		obj = obj.previousSibling;
		if(obj.tagName=='TD')indexThis++;		
	}
	if (this.getAttribute('direction') || this.direction) {
		direction = this.getAttribute('direction');
		if(navigator.userAgent.indexOf('Opera')>=0)direction = this.direction;
		if(direction=='ascending') {
			direction = 'descending';
			this.setAttribute('direction','descending');
			this.direction = 'descending';	
		}
		else {
			direction = 'ascending';
			this.setAttribute('direction','ascending');		
			this.direction = 'ascending';		
		}
	}
	else {
		direction = 'ascending';
		this.setAttribute('direction','ascending');
		this.direction = 'ascending';
	}
	var tableObj = this.parentNode.parentNode.parentNode;
	var tBody = tableObj.getElementsByTagName('TBODY')[0];
	var widgetIndex = tableObj.getAttribute('tableIndex');
	if(!widgetIndex)widgetIndex = tableObj.tableIndex;
	if(currentColumn)currentColumn.className='';
	document.getElementById('col' + widgetIndex + '_' + (indexThis+1)).className='highlightedColumn';
	currentColumn = document.getElementById('col' + widgetIndex + '_' + (indexThis+1));	
	var sortMethod = tableWidget_arraySort[widgetIndex][indexThis]; // N = numeric, S = String
	if(activeColumn[widgetIndex] && activeColumn[widgetIndex]!=this){
		if(activeColumn[widgetIndex])activeColumn[widgetIndex].removeAttribute('direction');			
	}
	activeColumn[widgetIndex] = this;
	
	var cellArray = new Array();
	var cellObjArray = new Array();
	for(var no=1;no<tableObj.rows.length;no++){ 
		var content= tableObj.rows[no].cells[indexThis].innerHTML+''; 
		cellArray.push(content); 
		cellObjArray.push(tableObj.rows[no].cells[indexThis]); 
	} 
		
	if(sortMethod=='N') { 
		cellArray = cellArray.sort(sortNumeric); 
	}
	else{ 
		cellArray = cellArray.sort(sortString); 
	} 
		
	if(direction=='descending'){ 
		for(var no=cellArray.length;no>=0;no--){
			for(var no2=0;no2<cellObjArray.length;no2++){ 
				if(cellObjArray[no2].innerHTML == cellArray[no] && !cellObjArray[no2].getAttribute('allreadySorted')){ 
					cellObjArray[no2].setAttribute('allreadySorted','1');	
					tBody.appendChild(cellObjArray[no2].parentNode);				
				}				
			}			
		} 
	}
	else{ 
		for(var no=0;no<cellArray.length;no++){ 
			for(var no2=0;no2<cellObjArray.length;no2++){ 
				if(cellObjArray[no2].innerHTML == cellArray[no] && !cellObjArray[no2].getAttribute('allreadySorted')){ 
					cellObjArray[no2].setAttribute('allreadySorted','1');	
					tBody.appendChild(cellObjArray[no2].parentNode);				
				}				
			}			
		}				
	} 
		
	for(var no2=0;no2<cellObjArray.length;no2++){ 
		cellObjArray[no2].removeAttribute('allreadySorted');		
	} 
 
	tableWidget_okToSort = true; 
		
		
} 
function initSortTable(objId,sortArray) {
	var obj = document.getElementById(objId);
	obj.setAttribute('tableIndex',tableWidget_tableCounter);
	obj.tableIndex = tableWidget_tableCounter;
	tableWidget_arraySort[tableWidget_tableCounter] = sortArray;
	var tHead = obj.getElementsByTagName('THEAD')[0];
	var cells = tHead.getElementsByTagName('TD');
	for(var no=0;no<cells.length;no++){
		if(sortArray[no]){
			cells[no].onclick = sortTable;	
		}else{
			cells[no].style.cursor = 'default';	
		}
	}		
	for(var no2=0;no2<sortArray.length;no2++){	/* Right align numeric cells */
		if(sortArray[no2] && sortArray[no2]=='N')obj.rows[0].cells[no2].style.textAlign='right';
	}		
	
	tableWidget_tableCounter++;
} 
////////////////////////////////////////////////////////////////////
/////////////////////// FIN ////////////////////////////////////////
/////////// SCRIPT PARA GRID DE ORDENAMIENTO ///////////////////////
////////////////////////////////////////////////////////////////////
function Imprimir() {
	menu = document.getElementById('dhtmlgoodies_menu');
	imprime = document.getElementById('Imprimir');
	menu.style.display='none';
	imprime.style.display='none';
	print();
	menu.style.display = '';
	imprime.style.display = '';
	//<div id="Imprimir" align="center"><a href="javascript:Imprimir();"><img src="images/imprimir.jpg" alt="Imprimir" width="22" height="22" border="0" /> Imprimir</a></div>
}

function RutDv(T){var M=0,S=1;for(;T;T=Math.floor(T/10))S=(S+T%10*(9-M++%6))%11;return S?S-1:'k';}
